import 'package:boss/models/package_group.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:boss/ui/widget/radioList/radio.dart' as radio;

class PackageGroupItem extends StatelessWidget {
  final PackageGroup data;
  final bool isSelected;
  final VoidCallback onTap;
  final VoidCallback onDelete;

  const PackageGroupItem({
    Key key,
    @required this.data,
    this.onTap,
    this.isSelected,
    this.onDelete,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: ShadowRadiusCard(
        margin: EdgeInsets.only(
          top: 30.w,
        ),
        padding: EdgeInsets.all(20.w),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              height: 60.w,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  RichText(
                    text: TextSpan(
                      text: data.groupName,
                      style: TextStyleConstant().normal_1_36,
                      children: [
                        WidgetSpan(child: SizedBox(width: 20.w)),
                        TextSpan(text: '${data.commodityFormList.length}选${data.count}', style: TextStyleConstant().normal_3_26),
                      ],
                    ),
                  ),
                  if (isSelected != null)
                    radio.Radio(
                      isSelected: isSelected,
                    ),
                  if (onDelete != null)
                    GestureDetector(
                      onTap: onDelete,
                      child: BaseImage(
                        'assets/image/delete_icon.png',
                        width: 30.w,
                        height: 30.w,
                      ),
                    ),
                ],
              ),
            ),
            for (final item in data.commodityFormList) CommodityRow(data: item)
          ],
        ),
      ),
    );
  }
}

class CommodityRow extends StatelessWidget {
  final CommodityFormList data;

  const CommodityRow({
    Key key,
    @required this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_2_26,
      child: Container(
        height: 50.w,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              data.commodityNameWithSku,
            ),
            Text(
              '${data.price == 0 ? '不加价' : '¥${AmountUtil.price2String(data.price)}'}',
            ),
          ],
        ),
      ),
    );
  }
}
